package com.eat.netty_server.hander;

import com.eat.netty_server.bean.Message;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

/**
 * @author CZF
 * @create 2022-04-05 21:08
 */
public class MessageServerHandler extends SimpleChannelInboundHandler<Message> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Message message) throws Exception {

    }

    //数据读取完毕
    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {

//        ctx.writeAndFlush(Unpooled.copiedBuffer("服务端接收到连接！", CharsetUtil.UTF_8));


    }

    //处理异常,一般是关闭通道
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.out.println("服务端连接close!");
        ctx.close();

    }
}
